
/**	\file	WindowSubMenu.cxx

	*	operate with main menu using WinAPI

*/

/////////////////////////////////////////////////////////////////////////////////////////
//
// Licensed is under the "New" BSD License.
//		License page - https://code.google.com/p/motioncodelibrary/wiki/LICENSE
//
// MotionCodeLibrary collection - https://code.google.com/p/motioncodelibrary/
//
// Author Sergey Solohin (Neill3d) 2014
//  e-mail to: s@neill3d.com
//		www.neill3d.com
/////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#include <windows.h>
//--- OR SDK include
#include <fbsdk/fbsdk.h>

// Subclass procedure
LRESULT APIENTRY EditSubclassProc(
    HWND hwnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam);
// iterate searching window class
BOOL CALLBACK EnumProc( HWND hwnd, LPARAM lParam );

//! menu item type
struct	MenuItem
{
	int		type;			//!> string / separator
	int		id;				//!> menu item id
	char	text[80];		//!> menu item caption
	bool	state;			//!> is item checked ?

	//! a constructor
	MenuItem()
	{
		type = MF_STRING;
		id = 0;
		state = false;
	}
};

////////////////////////////////////////////////////////////////////////////////
// MenuHandle
/*!
	*	 abstract class for menu handler (add new items and listen for notifiers)
*/
class		MenuHandle
{
public:
	//! item press notify
	virtual		int		ItemPress(int item) = 0;
	//! add items to the menu
	virtual		MenuItem		*ItemCollect(int *count) = 0;
};

////////////////////////////////////////////////////////////////////////////////
// ToolMenu
/*!
	*	 class for operating with a button and popup win32 menu with items
*/
class		ToolMenu : public FBComponent
{
public:
	// original MB window procedure
	WNDPROC mOrigEditProc;

public:

	//! constructor
	ToolMenu();

	//! set menu title
	void SetTitle(const char *title);
	//! set menu items handler
	void SetHandle(MenuHandle		*handle);
	//! item press notify
	void ItemPress(int item);
	//! popup menu
	void	Show();
	//! menu button click
	void	EventButtonClick( HISender pSender, HKEvent pEvent );

	//! return reference to the fbbutton control
	FBButton	&GetControl();
	//! use update when your tool is shown
	void Update();

private:
	//!	window title 
	FBString		mTitle;
	//! menu popup button
	FBButton		mButton;

	bool			mFirst;	// flag for updating window id

	//! items notify handler
	MenuHandle		*mHandle;

	//! prepare global variables
	void PrepareWndProc();
};


